package com.mming.sso.config;

import com.mming.sso.filter.BaseParamsCheckFilter;
import com.mming.sso.filter.TokenFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<BaseParamsCheckFilter> baseParamsCheckFilterFilterRegistrationBean() {
        FilterRegistrationBean<BaseParamsCheckFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(getBaseParamsCheckFilter());
        registration.addUrlPatterns("/*");
        registration.setName("BaseParamsCheckFilter");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean<TokenFilter> tokenFilterFilterRegistrationBean() {
        FilterRegistrationBean<TokenFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(getTokenFilter());
        filterRegistrationBean.addUrlPatterns("/user/*");
        filterRegistrationBean.setName("TokenFilter");
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }

    @Bean
    public TokenFilter getTokenFilter() {
        return new TokenFilter();
    }

    @Bean
    public BaseParamsCheckFilter getBaseParamsCheckFilter() {
        return new BaseParamsCheckFilter();
    }
}
